package com.shenhao.hpfa.util;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;

public class LatchHolder {

    private static final ConcurrentHashMap<String, CountDownLatch> LATCH_MAP = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<String, String> JSON_MAP = new ConcurrentHashMap<>();

    public static void addLatch(String key, CountDownLatch cdl) {
        LATCH_MAP.put(key, cdl);
    }

    public static void countdown(String key) {
        CountDownLatch countDownLatch = LATCH_MAP.get(key);
        if (countDownLatch != null) {
            countDownLatch.countDown();
        }
    }

    public static void putResp(String key, String respJson) {
        JSON_MAP.put(key, respJson);
    }

    public static String getResp(String key) {
        return JSON_MAP.remove(key);
    }

}
